package edu.uct.tamnd.viettourism.places;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import edu.uct.tamnd.viettourism.R;
import edu.uct.tamnd.viettourism.helper.DatabaseHelper;
import edu.uct.tamnd.viettourism.placesdetail.PlacesDetail;

public class PlacesList extends ListActivity {

	private ArrayList<PlacesItem> placesItems;
	private PlacesItemArrayAdapter adapter;
	DatabaseHelper mHelper;

	private int cityID;
	private int catID;
		
    private static final String TAG = "placesList";
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.places_list);
		setTitle("Danh sách địa danh");
		
		//openDatabase();
		
		Bundle bundle = getIntent().getExtras();
		cityID = bundle.getInt("cityID");
		catID = bundle.getInt("catID");
		Log.d(TAG, "Nhan cityID = " + cityID);
		Log.d(TAG, "Nhan catID = " + catID);
		
		placesItems = new ArrayList<PlacesItem>();
		placesItems = DatabaseHelper.readPlaces(cityID, catID);
		adapter = new PlacesItemArrayAdapter(PlacesList.this, R.layout.places_row_item, placesItems);
		setListAdapter(adapter);
							
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		Intent intent = new Intent(PlacesList.this, PlacesDetail.class);
		Bundle bundle = new Bundle();
		bundle.putInt("placesID", placesItems.get(position).getId());
		
		intent.putExtras(bundle);
		startActivity(intent);
		Log.d(TAG, "Gui places ID = "+ placesItems.get(position).getId());
	}
	
}
